<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>主页</title>
    <!-- 1. 导入CSS的全局样式 -->
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="${pageContext.request.contextPath}/js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <div style="margin: 5px">
        <a class="btn btn-primary" href="${pageContext.request.contextPath}/UserBlog/findBlogByPage">返回</a>
    </div>
    <p style="text-align: center;" class="bg-info">---</p>
    <br>

    <h3>共${requestScope.findBlogPageBean.totalCount}个搜索结果</h3>

    <%--展示用户的文章--%>
    <table border="1" class="table table-bordered table-hover">
        <c:forEach items="${requestScope.findBlogPageBean.list}" var="blog" varStatus="s">
            <a href="${pageContext.request.contextPath}/UserBlog/Blog?id=${blog.id}"><h4>${blog.title}</h4></a>>
            <blockquote>
                <c:if test="${blog.content.length()>=20}">
                    <p>${blog.content.substring(0,20)}...</p>
                </c:if>
                <c:if test="${blog.content.length()<20}">
                    <p>${blog.content}</p>
                </c:if>
            </blockquote>
        </c:forEach>
    </table>


    <%--下面这里是分页的数据--%>
    <div>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <%--这个li就是代表上一页的了--%>
                <c:if test="${requestScope.findBlogPageBean.currentPage==1}">
                <li class="disabled">
                        <%--这里是一个禁用,但页码为1的时候不让用--%>
                    </c:if>
                    <c:if test="${requestScope.findBlogPageBean.currentPage!=1}">
                <li>
                    </c:if>
                    <a href="${pageContext.request.contextPath}/UserBlog/findBlogPage?currentPage=${requestScope.findBlogPageBean.currentPage-1}&rows=5"
                       aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>


                <c:forEach begin="1" end="${requestScope.findBlogPageBean.totalPage}" var="i">
                    <%--上面这个显示的是激活状态
                    下面显示的是未激活状态 --%>
                    <c:if test="${requestScope.findBlogPageBean.currentPage==i}">
                        <li class="active"><a
                                href="${pageContext.request.contextPath}/UserBlog/findBlogPage?currentPage=${i}&rows=5">${i}</a>
                        </li>
                    </c:if>
                    <c:if test="${requestScope.findBlogPageBean.currentPage!=i}">
                        <li>
                            <a href="${pageContext.request.contextPath}/UserBlog/findBlogPage?currentPage=${i}&rows=5">${i}</a>
                        </li>
                    </c:if>
                </c:forEach>

                <c:if test="${requestScope.findBlogPageBean.currentPage==requestScope.findBlogPageBean.totalPage}">
                <li class="disabled">
                    </c:if>
                    <c:if test="${requestScope.findBlogPageBean.currentPage!=requestScope.findBlogPageBean.totalPage}">
                <li>
                    </c:if>
                    <a href="${pageContext.request.contextPath}/UserBlog/findBlogPage?currentPage=${requestScope.findBlogPageBean.currentPage+1}&rows=5"
                       aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>

                <span style="font-size: 25px;margin: 5px">
                共${requestScope.findBlogPageBean.totalCount}条记录,共${requestScope.findBlogPageBean.totalPage}页
                </span>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>
